/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * The software in this package is published under the terms of the GPL v2.0
 * license, a copy of which has been included with this distribution in the
 * LICENSE-GPL.txt file.
 */

package org.cemantika.exception;

import org.cemantika.management.ContextManager;
import org.cemantika.management.drools.DroolsContextualManipulation;

/**
 * FocusNotRegisteredException represents the error when the user call startProcess of
 * {@link DroolsContextualManipulation} but the focus has not been registered.
 * 
 * @author andersonfellipe
 */
public class FocusNotRegisteredException extends Exception {

    /**
     * Represents the serial of the {@link Exception}.
     */
    private static final long serialVersionUID = -6151061602654370921L;
    /**
     * Represents the focus the was not registered.
     */
    private String focusNotRegistered;

    public FocusNotRegisteredException(String focusNotRegistered) {
        this.focusNotRegistered = focusNotRegistered;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Throwable#getMessage()
     */
    @Override
    public String getMessage() {
        ContextManager contextManager = ContextManager.getInstance();
        String result = new String("Focus " + focusNotRegistered + " not registered. The ruleflow need to have the id equal its focus class name. ");
        if (!contextManager.getFociRegistered().isEmpty() && !contextManager.getFociRegistered().contains(focusNotRegistered)) {
            result = result + "The foci registered are: ";
            for (String focus : contextManager.getFociRegistered()) {
                result = result + focus + ", ";
            }
        } else {
            if (contextManager.getFociRegistered().contains(focusNotRegistered)) {
                result = result + "There are no focus of type " + focusNotRegistered + " registered.";
            } else {
                result = result + "There are no focus registered.";
            }
        }
        result = result.substring(0, result.length() - 2);
        return result;
    }

}
